package com.unc.allergyex;

import java.util.ArrayList;

import com.unc.allergyex.adapters.ComponentAdapter;
import com.unc.allergyex.helpers.ObjManager;
import com.unc.allergyex.objects.db.Component;
import com.unc.allergyex.objects.db.Dish;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

/**This is the activity for the dish-specific information screens.
 * This is a ListActivity, which uses itemspecific.xml as the overall layout
 * and uses expanded_item.xml as the item layout.  It is launched when 
 * the user taps on a dish item in the results view.  
 * @author Stephanie
 *
 */
public class DishBreakdown extends ListActivity {

	/**Sets up the layout elements for the activity. 
	 * Sets the header string to be the dishname and sets up the component adapter to use as the list adapter.   
	 * @see android.app.Activity#onCreate(android.os.Bundle)
	 */
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.itemspecific);
        
        Intent intent = getIntent();
		String dishId = intent.getStringExtra("dishId");
		Dish d = ObjManager.getDish(dishId);
        
        TextView tv = (TextView) findViewById(R.id.dishName);
        tv.setText(d.getName());
        
		ArrayList<Component> comps = d.getComponents();
		ComponentAdapter adapter = new ComponentAdapter(this, 4, comps);
		setListAdapter(adapter);
	}
	
	/**
	 * Causes this activity to close.  This method is called when the back button
	 * is tapped.
	 * @param v default parameter for this method
	 */
	public void returnButtonClicked(View v){
		this.finish();
	}
	
}
